import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sp_util/sp_util.dart';

import '../config/app_config.dart';
import '../config/constants.dart';
import '../config/lang/translation_service.dart';

class CommonSpUtil {
  // //存用户信息
  // static saveUserInfo({required UserInfo info}) {
  //   return SpUtil.putObject(Constants.userinfo, info);
  // }
  //
  // //获取用户信息
  // static UserInfo? getUserInfo() {
  //   return SpUtil.getObj(Constants.userinfo, (v) {
  //     return UserInfo.fromJson(v);
  //   });
  // }

  //隐私协议
  static bool getPrivacyDialog() {
    return SpUtil.getBool(Constants.privacyDialog, defValue: false) ?? false;
  }

  //保存隐私协议
  static savePrivacyDialog(bool privacyDialog) async {
    return await SpUtil.putBool(Constants.privacyDialog, privacyDialog);
  }

  /// 深色模式 0: 关闭 1: 开启 2: 随系统
  static int getThemeType() {
    return SpUtil.getInt(Constants.themeType) ?? 0;
  }

  /// 存深色模式
  static saveThemeType({required int type}) {
    return SpUtil.putInt(Constants.themeType, type);
  }

  /// 存语言配置
  static saveLanguageType({required Locale locale}) {
    return SpUtil.putString(Constants.launchType, locale.toString());
  }

  /// 获取语言配置
  static Locale getLanguageType() {
    String launchType = SpUtil.getString(Constants.launchType, defValue: TranslationService.zhCNLocale.toString()) ?? TranslationService.zhCNLocale.toString();
    List<String> launchList = launchType.split('_');
    String languageCode = launchList[0];
    String countryCode = launchList[1];
    return Locale(languageCode, countryCode);
  }

  /// 存服务器环境配置
  static saveServerEnvironment({required Environment environment}) {
    return SpUtil.putString(Constants.serverEnvironment, environment.name);
  }

  /// 获取服务器环境配置
  static Environment getServerEnvironment() {
    return Environment.fromString(SpUtil.getString(Constants.serverEnvironment) ?? '');
  }

}